<?php

namespace app\keeper\controller;

use app\common\business\Worker as WorkerBus;
use app\worker\validate\Worker;

class Login extends ApiBase
{
    //库管端登录
    public function keeperLogin()
    {
        if (!$this->request->isPost()){
            return show(config("status.error"),"请求方式错误");
        }
        //参数校验 1.原生方式 2.TP6验证机制
        $phone = $this->request->param("phone","","trim");
        $password = $this->request->param("password","","trim");
        $data = [
            'phone'=>$phone,
            'password'=>$password,
        ];
        $validate = new Worker();
        if(!$validate->check($data)){
            return show(config("status.error"),$validate->getError());
        }
        try {
            $Worker = new WorkerBus();
            $result = $Worker->KeeperLogin($data);
        }catch (\Exception $e){
            return show(config("status.error"),$e->getMessage());
        }
        if($result){
            return show(config("status.success"),"登录成功",$result);
        }else{
            return show(config("status.error"),"登录失败");
        }
    }
}
